using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;

/// <summary>
/// Summary description for processFAQ
/// </summary>
public class processFAQ:DBConnectionTool
{
	public processFAQ() : base()
	{
		//
		// TODO: Add constructor logic here
		//
	}

    public string getFAQID()
    {
        OpenCn();
        SqlCommand cmd = new SqlCommand("select right(max(FAQID),3) from FAQs", cn);
        String s = cmd.ExecuteScalar().ToString();
        Int32 result;
        if (Int32.TryParse(s, out result))
            result++;
        else
            result = 1;
        int l = result.ToString().Length;
        int count = 3 - l;
        string sresult = "FA";
        for (int i = 0; i < count; i++)
        {
            sresult = sresult + "0";
        }
        sresult = sresult + result;
        CloseCn();
        return sresult;
    }

    public DataTable getFAQ()
    {
        OpenCn();
        SqlDataAdapter da = new SqlDataAdapter("select * from FAQs",cn);
        DataTable dt = new DataTable("FAQs");
        da.Fill(dt);
        CloseCn();
        return dt;
    }

    public int insertFAQ(string FAQID, string FAQName, string FAQDetail)
    {
        OpenCn();
        SqlCommand cmd = new SqlCommand("Insert Into FAQs(FAQID,FAQName,FAQDetail) Values(@FAQID,@FAQName,@FAQDetail)", cn);
        cmd.Parameters.Add(new SqlParameter("@FAQID", SqlDbType.Char, 5));
        cmd.Parameters.Add(new SqlParameter("@FAQName", SqlDbType.NVarChar, 200));
        cmd.Parameters.Add(new SqlParameter("@FAQDetail", SqlDbType.NVarChar, 200));
        cmd.Parameters["@FAQID"].Value = FAQID;
        cmd.Parameters["@FAQName"].Value = FAQName;
        cmd.Parameters["@FAQDetail"].Value = FAQDetail;
        int result = cmd.ExecuteNonQuery();
        CloseCn();
        return result;
    }
    public int updateFAQ(string FAQID,string FAQName, string FAQDetail)
    {
        OpenCn();
        SqlCommand cmd = new SqlCommand("update FAQs set FAQName=@FAQName,FAQDetail=@FAQDetail where FAQID=@FAQID", cn);
        cmd.Parameters.Add(new SqlParameter("@FAQID", SqlDbType.Char, 5));
        cmd.Parameters.Add(new SqlParameter("@FAQName", SqlDbType.NVarChar, 200));
        cmd.Parameters.Add(new SqlParameter("@FAQDetail", SqlDbType.NVarChar, 200));
        cmd.Parameters["@FAQID"].Value = FAQID;
        cmd.Parameters["@FAQName"].Value = FAQName;
        cmd.Parameters["@FAQDetail"].Value = FAQDetail;
        int result = cmd.ExecuteNonQuery();
        CloseCn();
        return result;
    }

    public int deleteFAQ(string FAQID)
    {
        OpenCn();
        SqlCommand cmd = new SqlCommand("Delete FAQs Where FAQID ='" + FAQID + "'", cn);
        int result = cmd.ExecuteNonQuery();
        CloseCn();
        return result;
    }
}
